home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 201-225 / disk_217 / stevie / format_l.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  1KB  |  81 lines

  1. /*
  2.  * format_line() 
  3.  *
  4.  * Return a pointer to a string buffer containing a formated screen line.
  5.  *
  6.  * By G. R. (Fred) Walter    watmath!watcgl!grwalter 
  7.  */
  8.  
  9. #include "stevie.h"
  10.  
  11. char           *tab_expand = "                ";
  12.  
  13. char           *
  14. format_line(ptr, len)
  15.     register char  *ptr;
  16.     int            *len;
  17. {
  18.     register char  *dest;
  19.     register char   c;
  20.     register int    col;
  21.     char           *p_extra;
  22.     int             n_extra;
  23.     int             coff;    /* column offset */
  24.  
  25.     dest = IObuff;
  26.     col = 0;
  27.  
  28.     coff = P(P_NU) ? 8 : 0;
  29.  
  30.     n_extra = 0;
  31.     p_extra = NULL;
  32.  
  33.     for (;;) {
  34.     if (n_extra > 0) {
  35.         c = *p_extra++;
  36.         n_extra--;
  37.     } else {
  38.         c = *ptr++;
  39.         while (c >= 32 && c < 127) {
  40.         *dest++ = c;
  41.         col++;
  42.         if (col >= IOSIZE)
  43.             goto DONE_FORMAT_LINE;
  44.         c = *ptr++;
  45.         }
  46.         if (c == TAB) {
  47.         if (!P(P_LS)) {
  48.             /* tab amount depends on current column */
  49.             p_extra = tab_expand;
  50.             n_extra = (P(P_TS) - 1) - (col - coff) % P(P_TS);
  51.             c = ' ';
  52.         }
  53.         } else if ((n_extra = chars[c].ch_size - 1) > 0) {
  54.         p_extra = chars[c].ch_str;
  55.         c = *p_extra++;
  56.         } else if (c == NUL) {
  57.         if (P(P_NU)) {
  58.             *dest++ = '$';
  59.             col++;
  60.         }
  61.         break;
  62.         }
  63.     }
  64.     *dest++ = c;
  65.     col++;
  66.     if (col >= IOSIZE)
  67.         break;
  68.     }
  69. DONE_FORMAT_LINE:
  70.     if (col >= IOSIZE) {
  71.     dest--;
  72.     col--;
  73.     }
  74.     *dest = NUL;
  75.  
  76.     if (len != NULL)
  77.     *len = col;
  78.  
  79.     return (IObuff);
  80. }
  81.